<?php

namespace App\Middlewares;

use App\Exceptions\AuthException;
use Base\BaseController;
use Base\MiddlewareInterface;

class CheckIsAdminMiddleware implements MiddlewareInterface
{
    public static function handle(BaseController &$controller)
    {
        $path = $controller->request()->getUri()->getPath();
        $whitelist = config('whitelist.needAdmin');
        if (in_array($path, $whitelist) && $controller->userinfo['is_admin'] == 0) {
            throw new AuthException();
        }
    }
}
